﻿namespace HySoft.Cash.DB
{
    using Huayou.Common.Database;
    using Huayou.Utils;
    using HySoft.Cash.BaseClass;
    using HySoft.Cash.Structure;
    using System;
    using System.Data;

    public class TuptreportDB : BaseDB
    {
        public TuptreportDB(DBOperate oper) : base(oper)
        {
        }

        public bool Add(TuptreportDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { "INSERT INTO tUptReport (EmpSid,UptDate,EffectedCode,ChangedFrom,ChangedTo,ChangedBy,OrgSid) VALUES (", detail.EmpSid, ",'", StringUtils.ToSQL(detail.UptDate), "','", StringUtils.ToSQL(detail.EffectedCode), "','", StringUtils.ToSQL(detail.ChangedFrom), "','", StringUtils.ToSQL(detail.ChangedTo), "','", StringUtils.ToSQL(detail.ChangedBy), "',", detail.OrgSid, ")" });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Delete(int Sid)
        {
            int num = 0;
            string strSql = "DELETE FROM tUptReport where (Sid=" + Sid + ")";
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public bool Edit(TuptreportDT detail)
        {
            int num = 0;
            string strSql = string.Concat(new object[] { 
                "UPDATE tUptReport set EmpSid=", detail.EmpSid, ",UptDate='", StringUtils.ToSQL(detail.UptDate), "',EffectedCode='", StringUtils.ToSQL(detail.EffectedCode), "',ChangedFrom='", StringUtils.ToSQL(detail.ChangedFrom), "',ChangedTo='", StringUtils.ToSQL(detail.ChangedTo), "',ChangedBy='", StringUtils.ToSQL(detail.ChangedBy), "',OrgSid=", detail.OrgSid, " where (Sid=", detail.Sid, 
                ")"
             });
            try
            {
                try
                {
                    num = base.ExecuteForInt(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return (num == 1);
        }

        public TuptreportDT Get(int Sid)
        {
            TuptreportDT tdt = new TuptreportDT();
            try
            {
                try
                {
                    string strSql = "select * from tUptReport where (Sid=" + Sid + ")";
                    DataTable table = base.ExecuteForDataTable(strSql);
                    DataRow row = null;
                    if (table.Rows.Count >= 0)
                    {
                        row = table.Rows[0];
                        tdt.Sid = Convert.ToInt32(row["Sid"]);
                        tdt.EmpSid = Convert.ToInt32(row["EmpSid"]);
                        tdt.UptDate = Convert.ToString(row["UptDate"]);
                        tdt.EffectedCode = Convert.ToString(row["EffectedCode"]);
                        tdt.ChangedFrom = Convert.ToString(row["ChangedFrom"]);
                        tdt.ChangedTo = Convert.ToString(row["ChangedTo"]);
                        tdt.ChangedBy = Convert.ToString(row["ChangedBy"]);
                        tdt.OrgSid = Convert.ToInt32(row["OrgSid"]);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return tdt;
        }

        public DataTable GetList()
        {
            DataTable table = null;
            try
            {
                try
                {
                    string strSql = "select * from tUptReport";
                    table = base.ExecuteForDataTable(strSql);
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            finally
            {
            }
            return table;
        }
    }
}

